package com.juzipi.test;


import com.juzipi.demo.SecurityJwtApplication;
import com.juzipi.demo.pojo.Role;
import com.juzipi.demo.pojo.User;
import com.juzipi.demo.pojo.UserRole;
import com.juzipi.demo.service.RoleService;
import com.juzipi.demo.service.UserRoleService;
import com.juzipi.demo.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;

@SpringBootTest(classes = SecurityJwtApplication.class)
@RunWith(SpringRunner.class)
public class SecurityTest1 {



    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private UserRoleService userRoleService;


    @Test
    public void initData(){
        ArrayList<User> users = new ArrayList<>();
//        users.add(new User(1L,"admin",new BCryptPasswordEncoder().encode("pass"),null,null));
//        users.add(new User(2L,"user",new BCryptPasswordEncoder().encode("pass"),null,null));
//        User user = User.getInstance();


        ArrayList<Role> roles = new ArrayList<>();
//        roles.add(new Role(1L,"ROLE_ADMIN"));
//        roles.add(new Role(2L,"ROLE_USER"));

        ArrayList<UserRole> userRoles = new ArrayList<>();
        userRoles.add(new UserRole(1L,1L,1L));
        userRoles.add(new UserRole(2L,1L,2L));
        userRoles.add(new UserRole(3L,2L,2L));

        users.forEach(user -> userService.createUser(user));
        roles.forEach(role -> roleService.createRole(role));
        userRoles.forEach(userRole -> userRoleService.createUserRole(userRole));
    }

}
